﻿<UserControl xmlns:TeamExplorer="clr-namespace:Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;assembly=Microsoft.TeamFoundation.Controls"  
			 x:Class="TeamExplorer.Merge.MergeCandidates.MergeCandidatesPageView"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:tfs="clr-namespace:Microsoft.TeamFoundation.Controls.WPF;assembly=Microsoft.TeamFoundation.Controls"
			 xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.11.0" 
			 xmlns:localconverters="clr-namespace:TeamExplorer.Merge.Converters"
			 xmlns:converter="clr-namespace:Microsoft.TeamFoundation.Controls.WPF.Converters;assembly=Microsoft.TeamFoundation.Controls"
			 xmlns:this="clr-namespace:TeamExplorer.Merge.MergeCandidates"
			 xmlns:wpf="clr-namespace:Microsoft.TeamFoundation.Controls.WPF;assembly=Microsoft.TeamFoundation.Controls"  
			 mc:Ignorable="d" 
			 d:DesignHeight="600" d:DesignWidth="340"
			 >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Uid="VSResourceDictionary"
							Source="pack://application:,,,/Microsoft.TeamFoundation.Controls;component/WPF/SharedResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <CollectionViewSource x:Key="CollectionView.MergeList" d:DataContext="{StaticResource DesignTimeDataSource}" Source="{Binding MergeCandidatesCollection}">
                <CollectionViewSource.SortDescriptions>
                    <scm:SortDescription Direction="Ascending" PropertyName="CreationDate" />
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>
            <localconverters:ChangesetCommentConverter x:Key="Converters.ChangesetComment"/>
            <localconverters:NormalizeDateTimeConverter x:Key="Converters.NormalizeDateTime"/>
            <localconverters:EscapeMnemonicConverter x:Key="Converters.EscapeMnemonicConverter" />
            <converter:TrueToVisibleConverter x:Key="Converters.TrueToVisibility" x:Uid="converter:TrueToVisibleConverter"/>
            <converter:VisibilityInvertConverter x:Key="Converters.VisibilityInvertConverter" />
            <converter:NonEmptyStringToVisibleConverter x:Key="Converters.NonEmptyStringToVisibleConverter" />

            <ObjectDataProvider ObjectType="{x:Type this:DesignMergeCandidatesPage}" x:Key="DesignTimeDataSource" d:IsDataSource="True"/>
            <Style x:Key="Styles.ChangesetId" TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="11pt" />
                <Setter Property="Margin" Value="1" />
            </Style>
            <Style x:Key="Styles.Date" TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="9pt" />
                <Setter Property="Margin" Value="1" />
            </Style>
            <Style x:Key="Styles.StatusMessage" TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="11pt" />
                <Setter Property="Foreground" Value="DarkGray" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="TextWrapping" Value="Wrap" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Orientation="Vertical" Margin="0,3,0,0">

        <StackPanel x:Name="branchSelectionContainer" x:Uid="branchSelectionContainer" Margin="5,2,0,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="Source:" />
                <TeamExplorer:DropDownLink 
					x:Name="sourceBranchLink" 
					x:Uid="sourceBranchLink" 
					Grid.Column="1"
					Foreground="{DynamicResource BodyTextBrushKey}" 
					Text="{Binding Path=SourceBranch}"     
					IsEnabled="{Binding CanChooseSourceBranch}"   
					ShowArrow="{Binding CanChooseSourceBranch}"
					DropDownMenuCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=ShowSourceBranchDropDownCommand}"
					>
                    <TeamExplorer:DropDownLink.DropDownMenu>
                        <ContextMenu
							DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"
							ItemsSource="{Binding SourceBranches}" 
							Placement="Bottom"
							StaysOpen="False"
							HasDropShadow="True"
							>
                            <ContextMenu.ItemTemplate>
                                <DataTemplate>
                                    <MenuItem 
										Header="{Binding Path=Properties.RootItem.Item, Converter={StaticResource Converters.EscapeMnemonicConverter}}" 
										Command="{Binding DataContext.SelectSourceBranchCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
										CommandParameter="{Binding Path=.}"/>
                                </DataTemplate>
                            </ContextMenu.ItemTemplate>
                        </ContextMenu>
                    </TeamExplorer:DropDownLink.DropDownMenu>
                </TeamExplorer:DropDownLink>
                <Image
					Grid.Column="2"
					Visibility="{Binding IsWorkspaceSet, Mode=OneWay, Converter={StaticResource Converters.VisibilityInvertConverter}}"
					HorizontalAlignment="Right"
					Margin="2,0,4,0"
					Source="{Binding RelativeSource={RelativeSource AncestorType=UserControl,Mode=FindAncestor}, Path=ErrorIcon}" 
					Width="16" 
					Height="16">
                    <Image.ToolTip>
                        <TextBlock Text="Please set the workspace by selecting one in Pending Changes or Source Control Explorer to begin." />
                    </Image.ToolTip>
                </Image>
                <Image
					Grid.Column="2"
					Visibility="{Binding CurrentWorkspaceName, Mode=OneWay, Converter={StaticResource Converters.NonEmptyStringToVisibleConverter}}"
					HorizontalAlignment="Right"
					Margin="2,0,4,0"
					Source="{Binding RelativeSource={RelativeSource AncestorType=UserControl,Mode=FindAncestor}, Path=InformationIcon}" 
					Width="16" 
					Height="16">
                    <Image.ToolTip>
                        <TextBlock>
							<Run  Text="Workspace: " />
							<Run  Text="{Binding CurrentWorkspaceName, Mode=OneWay}" />
                        </TextBlock>
                    </Image.ToolTip>
                </Image>
            </Grid>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Target:" Width="50"/>
                <TeamExplorer:DropDownLink 
				x:Name="targetBranchLink" 
				x:Uid="targetBranchLink"                 
				Foreground="{DynamicResource BodyTextBrushKey}" 
				Text="{Binding Path=TargetBranch}"                              
				IsEnabled="{Binding CanChooseTargetBranch}"   
				ShowArrow="{Binding CanChooseTargetBranch}"
				DropDownMenuCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=ShowTargetBranchDropDownCommand}"
				>
                    <TeamExplorer:DropDownLink.DropDownMenu>
                        <ContextMenu
						DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"
						ItemsSource="{Binding TargetBranches}" 
						Placement="Bottom"
						StaysOpen="False"
						HasDropShadow="True"
						>
                            <ContextMenu.ItemTemplate>
                                <DataTemplate>
                                    <MenuItem 
									Header="{Binding Path=Properties.RootItem.Item, Converter={StaticResource Converters.EscapeMnemonicConverter}}" 
									Command="{Binding DataContext.SelectTargetBranchCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
									CommandParameter="{Binding Path=.}"/>
                                </DataTemplate>
                            </ContextMenu.ItemTemplate>
                        </ContextMenu>
                    </TeamExplorer:DropDownLink.DropDownMenu>
                </TeamExplorer:DropDownLink>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
                <Button Content="Find Changesets" Command="{Binding GetMergeCandidatesCommand, Mode=OneWay}" />
                <TeamExplorer:TextLink 
					x:Uid="saveAsDefault"  
					x:Name="saveAsDefault" 
					Margin="12,0,0,0"
					Text="Save as default" 
					VerticalAlignment="Center"
					ToolTip="Save source and target branch as the default selection"
					Command="{Binding SaveDefaultBranchesCommand, Mode=OneWay}" />
            </StackPanel>
        </StackPanel>

        <StackPanel
			HorizontalAlignment="Right"
			Margin="2,0,4,0"
			Width="60"
			Visibility="{Binding ShowResults, Converter={StaticResource Converters.TrueToVisibility}}"
			Orientation="Horizontal">
            <TextBlock Text="sort " HorizontalAlignment="Left" Width="25" FontSize="9pt" Foreground="{StaticResource ItemTextBrushKey}" />
            <TeamExplorer:TextLink 
					x:Uid="sortLink"  
					x:Name="sortLink" 
					Text="asc"
					VerticalAlignment="Center"
					Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=SortCommand, Mode=OneWay}"
				CommandParameter="{StaticResource CollectionView.MergeList}"
				/>
        </StackPanel>

        <ListBox
			x:Name="changesetList"
			Visibility="{Binding ShowResults, Converter={StaticResource Converters.TrueToVisibility}}"
			Margin="0,5,0,10"
			ItemsSource="{Binding Source={StaticResource CollectionView.MergeList}}" 
			d:DataContext="{StaticResource DesignTimeDataSource}"
			ScrollViewer.HorizontalScrollBarVisibility="Hidden"
			Height="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=Height}"
			BorderThickness="0"
			ScrollViewer.VerticalScrollBarVisibility="Auto"
			HorizontalContentAlignment="Left"
			VerticalContentAlignment="Stretch"
			>
            <ListBox.Resources>
                <Style BasedOn="{StaticResource ListBoxItemStyle}" TargetType="{x:Type ListBoxItem}">
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,6,3" Text="Changeset ID:" FontWeight="Bold"/>
                                <TextBlock Grid.Row="0" Grid.Column="1" Margin="0,0,0,3" Text="{Binding Path=ChangesetId}"/>

                                <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,6,3" Text="Date:" FontWeight="Bold"/>
                                <TextBlock Grid.Row="1" Grid.Column="1" Margin="0,0,0,3" Text="{Binding Path=CreationDate}"/>

                                <TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,6,3" Text="Comment:" FontWeight="Bold"/>
                                <TextBlock Grid.Row="2" Grid.Column="1" Margin="0,0,0,3" Text="{Binding Path=Comment}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" MaxWidth="500"/>
                            </Grid>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Height="25">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="70" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock 
							    Margin="3,0,0,0"
							    Padding="2,2,2,0" 
							    VerticalAlignment="Center" 
							    HorizontalAlignment="Center" 
                            ToolTip="Discard"
							    >
								<Hyperlink 
									FontSize="11pt" 
									Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}, Path=DataContext.DiscardCommand, Mode=OneWay}" 
									CommandParameter="{Binding ChangesetId, Mode=OneWay}">
									<TextBlock Text="X" Foreground="Red" TextDecorations="None" />
									<Hyperlink.Style>
										<Style BasedOn="{StaticResource ActionLink}" TargetType="{x:Type Hyperlink}">
											<Style.Triggers>
												<DataTrigger Binding="{Binding JustMerged}" Value="True">
													<Setter Property="TextDecorations" Value="Strikethrough" />
													<Setter Property="IsEnabled" Value="False" />
												</DataTrigger>
											</Style.Triggers>
										</Style>
									</Hyperlink.Style>
								</Hyperlink>
						</TextBlock>
                            <TextBlock 
                                Grid.Column="1"
							    Margin="3,0,0,0"
							    Padding="2" 
							    VerticalAlignment="Center" 
							    HorizontalAlignment="Center" 
							    >
								<Hyperlink 
									FontSize="11pt" 
									Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}, Path=DataContext.MergeChangesetCommand, Mode=OneWay}" 
									CommandParameter="{Binding ChangesetId, Mode=OneWay}">
									<TextBlock Text="{Binding ChangesetId}" TextDecorations="None" />
									<Hyperlink.Style>
										<Style BasedOn="{StaticResource ActionLink}" TargetType="{x:Type Hyperlink}">
											<Style.Triggers>
												<DataTrigger Binding="{Binding JustMerged}" Value="True">
													<Setter Property="TextDecorations" Value="Strikethrough" />
													<Setter Property="IsEnabled" Value="False" />
												</DataTrigger>
											</Style.Triggers>
										</Style>
									</Hyperlink.Style>
								</Hyperlink>
						</TextBlock>
                        
                        <TextBlock 
							Grid.Column="2"
							Padding="2"
							VerticalAlignment="Center"
							HorizontalAlignment="Center" 
							Text="{Binding CreationDate, Converter={StaticResource Converters.NormalizeDateTime}}"
							Style="{StaticResource Styles.Date}" 
							/>
                        <Border 
							Grid.Column="3" 
							Margin="3,0,0,0" 
							BorderThickness="1,0,0,0" 
							BorderBrush="{StaticResource ItemTextBrushKey}">
                            <TextBlock 
								Margin="3,0,0,0"
								VerticalAlignment="Center"
								HorizontalAlignment="Left" 
								Text="{Binding Comment, Mode=OneWay, Converter={StaticResource Converters.ChangesetComment}}" 
								TextTrimming="CharacterEllipsis" 
								Padding="2"
								/>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <TextBlock
			x:Name="loadingMessage" 
			Padding="50"
			Style="{StaticResource Styles.StatusMessage}"
			Visibility="{Binding IsBusy, Converter={StaticResource Converters.TrueToVisibility}}"
			Text="Retrieving changesets..." >
			
		<Hyperlink 
			Command="{Binding Path=CancelCommand, Mode=OneWay}"
			Style="{StaticResource ActionLink}" 
			FontSize="11pt">
			<TextBlock Text="cancel" FontSize="9pt" />
		</Hyperlink>
			</TextBlock>
        <StackPanel 
			Margin="50"
			Orientation="Horizontal" 
			Visibility="{Binding NoResultsAvailable, Converter={StaticResource Converters.TrueToVisibility}}"
			HorizontalAlignment="Center"
			VerticalAlignment="Center">
            <Image
				Source="{Binding RelativeSource={RelativeSource AncestorType=UserControl,Mode=FindAncestor}, Path=SuccessfulIcon}" 
				Width="16" 
				Height="16"
				/>
            <TextBlock
				x:Name="noResultsMessage" 
				Margin="3,0,0,0"
				Style="{StaticResource Styles.StatusMessage}"
				Text="No changesets to merge"
			/>
        </StackPanel>
        <StackPanel 
			Margin="50"
			Orientation="Horizontal" 
			Visibility="{Binding OperationCancelled, Converter={StaticResource Converters.TrueToVisibility}}"
			HorizontalAlignment="Center"
			VerticalAlignment="Center">
            <Image
				Source="{Binding RelativeSource={RelativeSource AncestorType=UserControl,Mode=FindAncestor}, Path=InformationIcon}" 
				Width="16" 
				Height="16"
				/>
            <TextBlock
				x:Name="cancelledMessage" 
				Margin="5,-1,0,0"
				Style="{StaticResource Styles.StatusMessage}"
				Text="Request was cancelled by user"
			/>
        </StackPanel>
    </StackPanel>
</UserControl>
